var calPoints = function(arr) {
  let result = []

  arr.forEach(item => {
    switch (item) {
      case 'C':
        result.pop()
        break
      case 'D':
        result.push([...result].pop() * 2)
        break
      case '+':
        const copy = JSON.parse(JSON.stringify(result))
        result.push(copy.pop() + copy.pop())
        break
      default:
        result.push(+item)
    }
  })

  return result.reduce((acc, cur) => acc + cur)
}
